home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-11-12 | 7.8 KB | 318 lines | [TEXT/PJMM] |
- {****************************************************}
- {}
- { CStarterApp.p }
- {}
- { Application methods for a typical application. }
- {}
- { Copyright © 1989, Symantec Corporation. All rights reserved. }
- {}
- {****************************************************}
-
-
- unit CStarterApp;
-
- interface
-
- uses
- TCL, StarterIntf, {}
- CDlog, UExampleDlog; {For example dialog}
-
- implementation
-
-
- {**}
- { * IStarterApp}
- { *}
- { * Initialize the application. Your initialization method should}
- { * at least call the inherited method. If your application class}
- { * defines its own instance variables or global variables, this}
- { * is a good place to initialize them.}
- { *}
- { **}
-
- procedure CStarterApp.IStarterApp;
-
- begin
- IApplication(4, 20480, 2048);
-
- { The parameters to IApplication are the number of times to call MoreMasters, }
- { the number of bytes of heap space to reserve for monitoring }
- { low memory situations, and the credit limit for memory requests. }
- { Four (4) is a reasonable number of MoreMasters calls, }
- { but you should determine a good number for your application }
- { by observing the heap using Lightsbug, }
- { TMON, or Macsbug. Set this parameter to zero, give your }
- { program a rigorous work-out, then look at the heap and count }
- { how many master pointer blocks have been allocated. Master }
- { pointer blocks are nonrelocatable and have a size of $100 }
- { (hex). You should call MoreMasters at least this many }
- { times -- add a few extra just to be safe. The purpose of all }
- { this preflighting is to prevent heap fragmentation. You }
- { don't want the Memory Manager to call MoreMasters and }
- { create a nonrelocatable block in the middle of your heap. By }
- { calling MoreMasters at the very beginning of the program, }
- { you ensure that these blocks are allocated in a group at the }
- { bottom of the heap. }
- { The memory reserve is a safeguard for handling low memory }
- { conditions and is used by the GrowMemory method in }
- { CApplication (check there for more comments). In general, }
- { your program should never request a memory block greater }
- { than this reserve size without explicitly checking in }
- { advance whether there is enough free memory to satisfy the }
- { the request. }
- { The credit limit specifies a cut-off level for memory }
- { requests which can tap the memory reserve. Requests larger }
- { than this size will not use the memory reserve when the }
- { system pleads for more memory. }
-
- end;
-
-
- {**}
- { * MakeDesktop}
- { *}
- { * Build a desktop that supports modal dialogs. }
- { *}
- { **}
- procedure CStarterApp.MakeDesktop; {For example dialog}
- var
- aDeskTop: CDModalDesktop;
-
- begin
- new(aDesktop); { Use a CDModalDesktop Desktop }
- gDeskTop := aDeskTop; { Set the global variable }
- gDesktop.IDesktop(SELF); { Send the init message }
- end;
-
- {**}
- { * SetUpFileParameters}
- { *}
- { * In this routine, you specify the kinds of files your}
- { * application opens.}
- { *}
- { **}
-
- procedure CStarterApp.SetUpFileParameters;
-
- begin
-
- inherited SetUpFileParameters; { Be sure to call the default method }
-
- {*}
- { ** sfNumTypes is the number of file types}
- { ** your application knows about.}
- { ** sfFileTypes[] is an array of file types.}
- { ** You can define up to 4 file types in}
- { ** sfFileTypes[].}
- { **}
- { *}
-
- sfNumTypes := 1;
- sfFileTypes[0] := 'TEXT';
-
- {*}
- { ** Although it's not an instance variable,}
- { ** this method is a good place to set the}
- { ** gSignature global variable. Set this global}
- { ** to your application's signature. You'll use it}
- { ** to create a file (see CFile.CreateNew).}
- { **}
- { *}
-
- gSignature := '????';
- end;
-
-
-
- {**}
- { * SetUpMenus }
- { *}
- { * Set up menus which must be created at run time, such as a}
- { * Font menu. You can eliminate this method if your application}
- { * does not have any such menus.}
- { *}
- {**}
-
- procedure CStarterApp.SetUpMenus;
- begin
-
- inherited SetUpMenus; { Superclass takes care of adding }
- { menus specified in a MBAR id = 1 }
- { resource }
-
- { Add your code for creating run-time menus here }
- end;
-
-
- {**}
- { * DoCommand}
- { *}
- { * Your application will probably handle its own commands.}
- { * Remember, the command numbers from 1-1023 are reserved.}
- { * The file TCL.p contains all the predefined TCL commands.}
- { *}
- { * Be sure to call the default method, so you can get}
- { * the default behavior for standard commands.}
- { *}
- { **}
-
- procedure CStarterApp.DoCommand (theCommand: longint);
-
- begin
- case theCommand of
- cmdAbout: {For example dialog}
- begin
- DoExampleDlog;
- end;
-
- otherwise { Invoke inherited method }
- inherited DoCommand(theCommand); { to handle other commands }
-
- end;
- end;
-
-
- {**}
- { *}
- { * UpdateMenus }
- { *}
- { * Perform menu management tasks}
- { *}
- {**}
-
- procedure CStarterApp.UpdateMenus;
- var
- topWindow: CWindow;
- modal: boolean;
-
- begin
- inherited UpdateMenus; { Enable standard commands }
-
- { Enable the commands handled by your Application class }
-
- { ----------------------------------------------------------------------------- }
- { The rest of this method was added by John Cardinal for the CDlog example application }
- { ----------------------------------------------------------------------------- }
-
- { Support for modal windows:}
- { If top window is modal, we must disable items that are not }
- { valid while the modal window is up. }
-
- topWindow := gDeskTop.GetTopWindow;
- if Member(topWindow, CDlogWind) then
- modal := CDlogWind(topWindow).GetModal
- else
- modal := FALSE;
-
- if modal then begin
- gBartender.DisableCmd(cmdNew);
- gBartender.DisableCmd(cmdOpen);
- gBartender.DisableCmd(cmdClose);
- gBartender.DisableCmd(cmdAbout);
- gBartender.DisableCmd(cmdToggleClip);
- end
- else
- gBartender.EnableCmd(cmdAbout);
- end;
-
-
- {**}
- { * Exit}
- { *}
- { * Chances are you won't need this method.}
- { * This is the last chance your application gets to clean up}
- { * things like temporary files before terminating.}
- { *}
- { **}
-
- procedure CStarterApp.Exit;
-
- begin
- { your exit handler here }
- end;
-
-
- {**}
- { * CreateDocument}
- { *}
- { * The user chose New from the File menu.}
- { * In this method, you need to create a document and send it}
- { * a NewFile message.}
- { *}
- { **}
-
- procedure CStarterApp.CreateDocument;
-
- var
- theDocument: CStarterDoc;
-
- begin
-
- new(theDocument);
-
- {*}
- { ** Send your document an initialization}
- { ** message. The first argument is the document's}
- { ** supervisor (the application). The second}
- { ** argument is TRUE if the document is printable.}
- { **}
- { *}
-
- theDocument.IStarterDoc(SELF, TRUE);
-
- {*}
- { ** Send the document a NewFile message.}
- { ** The document will open a window, and}
- { ** set up the heart of the application.}
- { **}
- { *}
-
- theDocument.NewFile;
- end;
-
-
- {**}
- { * OpenDocument}
- { *}
- { * The user chose Open… from the File menu.}
- { * In this method you need to create a document}
- { * and send it an OpenFile message.}
- { *}
- { * The macSFReply is a good SFReply record that contains}
- { * the name and vRefNum of the file the user chose to}
- { * open.}
- { *}
- { **}
-
- procedure CStarterApp.OpenDocument (macSFReply: SFReply);
-
- var
- theDocument: CStarterDoc;
-
- begin
-
- new(theDocument);
-
- {*}
- { ** Send your document an initialization}
- { ** message. The first argument is the document's}
- { ** supervisor (the application). The second}
- { ** argument is TRUE if the document is printable.}
- { **}
- { *}
-
- theDocument.IStarterDoc(SELF, TRUE);
-
- {*}
- { ** Send the document an OpenFile message.}
- { ** The document will open a window, open}
- { ** the file specified in the macSFReply record,}
- { ** and display it in its window.}
- { **}
- { *}
-
- theDocument.OpenFile(macSFReply);
- end;
-
-
- end.